package member.order.service;

import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.common.service.Service;
import m.system.exception.MException;
import m.system.util.StringUtil;
import member.base.model.StoreInfo;
import member.order.model.StorePlan;

public class StorePlanService extends Service {
    /**
     * 获取店铺年度的计划
     */
    public StorePlan get(String storeOid, String year) throws Exception {
        if(StringUtil.isSpace(storeOid)||StringUtil.isSpace(year)) throw new MException("参数错误");
        StorePlan model= ModelQueryList.getModel(StorePlan.class,new String[]{"*","inputStore.*"},
            QueryCondition.and(
                QueryCondition.eq("inputStore.oid",storeOid),
                QueryCondition.eq("planYear",year)
            )
        );
        if(null==model){
            model=new StorePlan();
            model.setInputStore(new StoreInfo());
            model.getInputStore().setOid(storeOid);
            model.setPlanYear(year);
            saveModel(model);
            return get(storeOid,year);
        }else{
            return model;
        }
    }
}
